using Common.Core;
using Common.Unity.Configuration;
using Microsoft.Practices.ObjectBuilder2;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Configuration;

namespace Common.Unity.Configuration
{
	class TypeInjectionElement : Microsoft.Practices.Unity.Configuration.TypeInjectionElement
	{
		public override void Configure(IUnityContainer container)
		{
			using ( ThreadLocalStorage.Push( new NamedTypeBuildKey( ParentElement.MapTo ?? ParentElement.Type, ParentElement.Name ) ) )
			{
				using ( ThreadLocalStorage.Push( TypeResolver ) )
				{
					base.Configure(container);
				}
			}
		}
	}
}